<?php
/*
 * @Author: your name
 * @Date: 2020-11-16 14:16:14
 * @LastEditTime: 2020-12-28 09:44:36
 * @LastEditors: Please set LastEditors
 * @Description: 防火墙规则预览
 * @FilePath: /special/application/adminapiv3/controller/module_manage/netfilter/RulePreviewController.php
 */
namespace app\adminapiv3\controller\module_manage\netfilter;

use app\adminapiv3\service\module_manage\netfilter\RulePreviewService;

class RulePreviewController extends NetfilterBaseController
{
    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-11-16 14:17:46
     */
    public function list (\think\Request $request)
    {
        $input = $request->only(['type','rule_id','content','host_id'], 'post');
        $this->validate($input, 'RulePreview.list');

        $RulePreviewService = new RulePreviewService();
        $data = $RulePreviewService->list($input);

        return $this->jsonOutPut($data);
    }

    /**
     * @name: 规则排序
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-11-16 14:18:18
     */
    public function sort (\think\Request $request)
    {
        $input = $request->only(['id','host_id'], 'post');
        $this->validate($input, 'RulePreview.sort');

        $RulePreviewService = new RulePreviewService();
        $RulePreviewService->sort($input);

        return $this->jsonOutPut();
    }

    /**
     * @name: 向客户端推送规则
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-11-25 13:07:27
     */
    public function pushToClient (\think\Request $request)
    {
        $input = $request->only(['host_id'], 'post');
        $this->validate($input, 'RulePreview.push');
        
        $RulePreviewService = new RulePreviewService();
        $RulePreviewService->push($input['host_id']);
        //下发命令 查询规则列表
        $this->sendCommandToClient('netfilter','downloadRules');
        return $this->jsonOutPut();
    }
}